/*-------------------------------------------------------------------------------
* file:     app_timer.c
* brief:    application
* copyright Copyright (C) 2020-2022 @ NanoIC
* Date:     2022-08-15
* Version:  V1.00
* Author:   JMH
*-------------------------------------------------------------------------------*/

/* include ----------------------------------------------------------------*/
#include "app_timer.h"
#include "app_keyboard_server.h"

/* externs variablesr------------------------------------------------------*/

/* Private variablesr------------------------------------------------------*/
/**
 * @brief 上电标志
 */
//bool poweron_flag ;

/**
 * @brief 键盘PCBA测试
 */
uint8_t global_key_test_status;


/* Private function--------------------------------------------------------*/
/**
 * @brief 定时器初始化
 * 
 */
void app_timer_init(void)
{
    csi_bt_timer_init(BT0, 100);				//初始化BT0, 定时100us； BT定时，默认采用PEND中断
    csi_vic_set_prio((int32_t)BT0_IRQ_NUM, 0);
    csi_bt_start(BT0);							//启动定时器0
    global_key_test_status = 0x01;
}

/**
 * @brief 定时器低功耗
 * 
 */
void app_timer_sleep(void)
{
    csi_bt_stop(BT0);                   //关闭定时器0
}
uint8_t t=0;
/**
 * @brief 定时器终端回调
 * 
 * @param ptBtBase 
 */
void app_timer_irqhandler(csp_bt_t *ptBtBase)
{
    if(ptBtBase == BT0)
    {
        app_iic_init_timer_tick_0_1ms_handler();
        app_uart_timer_tick_0_1ms_handler();
        #if APP_KEYBOARD_ENABLE
        if(global_key_test_status)
        {
            app_key_timer_tick_0_1ms_callback();
        }
        #endif
        app_lowpower_timer_tick_0_1ms_callback();
        app_flash_log_timer_tick_0_1_ms_callback();
        app_sleep_timer_tick_0_1ms_callback();
		app_gsensor_timer_tick_0_1ms_callback();
		app_ota_timer_tick_0_1ms_handler();
    }
}

/**t
 * @brief 键盘上传上电工作通知
 * 
 */

void app_power_on_notice(void)
{
    //同步包  
//    one_wrie_bus_app_send_syn_beat();
//        bool state ;
//        uint8_t len=0;
//		bool flag = true;
//		if(flag)
//		{
//			
//			
//		}

		keyboard_connect();

}

/**
 * @brief 低功耗处理
 * 
 * @param on true 唤醒 ，false 休眠
 */
void app_timer_sleep_and_weakup_set(bool on)
{
    if(on)
    {
        app_timer_init();
    }else
    {
        app_timer_sleep();
    }
}

